{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1af73c85",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "func = np.poly1d([1,14,60,70,0])\n",
    "\n",
    "def NewtonIteration(func, epsilon):\n",
    "    f_1 = func.deriv()\n",
    "    f_2 = func.deriv().deriv()\n",
    "    x = np.random.randint(1,100,1)[0]\n",
    "    x1 = 0\n",
    "    while(np.abs(x1 - x) > epsilon):\n",
    "        if(x1 != 0):\n",
    "            x = x1\n",
    "        x1 = x - (f_1(x))/(f_2(x))\n",
    "    return func(x1)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e2c52b02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-24.369601567355037"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NewtonIteration(func, 1e-5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
